package com.example.ywj.toutiao.utils;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import androidx.appcompat.app.AppCompatActivity;

public class Util {
    //获取随机数数组
    public static int[] randomCommon(int min, int max, int n){
        if (n > (max - min + 1) || max < min) {
            return null;
        }
        int[] result = new int[n];
        int count = 0;
        while(count < n) {
            int num = (int) (Math.random() * (max - min)) + min;
            boolean flag = true;
            for (int j = 0; j < n; j++) {
                if(num == result[j]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                result[count] = num;
                count++;
            }
        }
        return result;
    }
    //检查密码6-16位，数组字母和特殊字符的两种
    public static boolean checkPwd(String newPwd) {
        int i = newPwd.matches(".*\\d+.*") ? 1 : 0;
        int j = newPwd.matches(".*[a-zA-Z]+.*") ? 1 : 0;
        int k = newPwd.matches(".*[_+|<>,.?/:;'\\[\\]{}\"]+.*") ? 1 : 0;
        int l = newPwd.length();

        if (i + j + k < 2 || l < 6 || l > 16) {
            return false;
        }
        return true;
    }
    public static void hideKeyboard(AppCompatActivity context) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        // 隐藏软键盘
        imm.hideSoftInputFromWindow(context.getWindow().getDecorView().getWindowToken(), 0);
    }
    public static void showKeyBoard(View view){
        InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if(imm!=null){
            view.requestFocus();
            imm.showSoftInput(view,0);
        }
    }

}
